package com.shudes.eval;

import java.util.*;

import com.shudes.game.*;

public class EquityObservation {

	protected EquityInput input;
	protected Map<HoleCards, GameResult> results;
	protected Map<HoleCards, HandStrength> hands;
	protected Board trialBoard; 
	
	public EquityObservation(EquityInput input) {
		this.input=input;
		
		results = new HashMap<HoleCards, GameResult>();		
		hands = new HashMap<HoleCards, HandStrength>(); 
		results.put(input.getHero(), null); 
		for(HoleCards hc : input.getVillians()) { 
			results.put(hc, null); 
		}
	}
	
	public EquityObservation(EquityInput input, Board trialBoard) { 
		this(input); 
		this.trialBoard=trialBoard; 
	}
		
	Map<HoleCards, GameResult> getResultMap() { 
		return results; 
	}
	
	Map<HoleCards, HandStrength> getHandStrengthMap() { 
		return hands; 
	}	
	
	Board getTrialBoard() { 
		return trialBoard; 
	}
	
	public void setWinner(HoleCards hc) { 
		results.put(hc, GameResult.WIN); 
		setLosers(hc); 
	}
	
	public void setTie(Set<HoleCards> hc) { 
		for(HoleCards c : hc ) { 
			results.put(c, GameResult.TIE); 
			
		}
		
		this.setLosers(hc); 
	}
	
	public Map<HoleCards, GameResult> getObservationMap() { 
		return results; 
	}
	
	public HoleCards getWinner() {
		for(HoleCards hc : results.keySet()) {
			if(GameResult.WIN.equals(results.get(hc))) 
				return hc; 
		}
		
		return null;
	}
	
	public Set<HoleCards> getTie() { 
		Set<HoleCards> set; 
		
		set = new HashSet<HoleCards>(); 
		for(HoleCards hc : results.keySet()) { 
			if(GameResult.TIE.equals(results.get(hc))) {
				set.add(hc); 
			}		
		}
		
		return set;
	}
	
	public Integer getTieCount() {
		Integer count = 0; 
		
		for(GameResult r : results.values()) { 
			if(GameResult.TIE.equals(r))
				count++; 
		}
		return count; 
	}
	
	public boolean wasSplitPot() { 
		return results.values().contains(GameResult.TIE); 
	}
		
	protected void setLosers(HoleCards winner) { 
		HashSet<HoleCards> s = new HashSet<HoleCards>();
		s.add(winner); 		
		setLosers(s); 
	}
	
	protected void setLosers(Set<HoleCards> winners) { 
		for(HoleCards hc : results.keySet()) { 
			if(!winners.contains(hc)) { 
				results.put(hc, GameResult.LOSS); 
			}
		}
	}

}
